home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
InstantUpgradePro
/
InstantUpgradeProINIT.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-22
|
17KB
|
589 lines
/*
Written by Steve Bollinger and Cameron Esfahani at MacHack '96
*/
#include <A4Stuff.h>
#include <SetUpA4.h>
#include <Menus.h>
#include <Resources.h>
#include <LowMem.h>
#include <Windows.h>
#include <Traps.h>
#define kDialogUserItem1 1
#define kDialogUserItem2 2
#define kDialogUserItem3 3
#define kDialogUserItem4 4
#define kDialogUserItem5 5
#define kDialogUserItem6 6
#define kDialogUserItem7 7
#define kDialogUserItem8 8
#define kTextBoxes 8
Handle ReturnA0(void) = {0x2008};
typedef pascal WindowPtr (*NewCWindowProcPtr)(void *wStorage, const Rect *boundsRect,
ConstStr255Param title, Boolean visible, short procID, WindowRef behind,
Boolean goAwayFlag, long refCon);
typedef pascal void (*ShowWindowProcPtr)(WindowPtr window);
typedef pascal long (*MenuSelectProcPtr)(Point select);
typedef pascal unsigned short (*IsDialogEventProcPtr)(const EventRecord* theEvent);
typedef pascal Boolean (*DialogSelectProcPtr)(const EventRecord* theEvent, DialogPtr* theDialog, short* itemHit);
typedef pascal void (*DisposeWindowProcPtr)(WindowPtr window);
//typedef pascal void (*StdTextProcPtr)(short count, const void* textAddr, Point numer, Point denom);
pascal static long MenuSelectPatch(Point select);
//pascal static asm long MenuSelectPatch(Point select);
pascal static void TEInitPatch(void);
pascal static WindowPtr NewCWindowPatch(void *wStorage, const Rect *boundsRect,
ConstStr255Param title, Boolean visible, short procID, WindowRef behind,
Boolean goAwayFlag, long refCon);
pascal static void ShowWindowPatch(WindowPtr window);
pascal static unsigned short IsDialogEventPatch(const EventRecord* theEvent);
pascal static Boolean DialogSelectPatch(const EventRecord* theEvent, DialogPtr* theDialog, short* itemHit);
pascal static void DisposeWindowPatch(WindowPtr whichWindow);
pascal static void UserItemHandler(WindowRef theWindow, short item);
pascal static void ReplStdText(short count, char* textAddr, Point numer, Point denom);
pascal static void ReplRect(GrafVerb verb, Rect *r);
UniversalProcPtr gOldTEInit;
MenuSelectProcPtr gOldMenuSelect;
NewCWindowProcPtr gOldNewCWindow;
ShowWindowProcPtr gOldShowWindow;
IsDialogEventProcPtr gOldIsDialogEvent;
//DialogSelectProcPtr gOldDialogSelect;
DisposeWindowProcPtr gOldDisposeWindow;
WindowPtr gAboutMacWindow;
DialogPtr gFakeAboutMacWindow;
Handle gFakeWindowUserItemDITL;
//Handle gFakeWindowEditTextItemDITL;
Rect gFakeWindowTextRect;
DialogRecord gFakeAboutMacWindowStorage;
Boolean gShouldCreateWindow;
short gFakeItems;
Boolean gEditTextItemIsEnabled;
CQDProcs gReplacementProcs;
QDTextUPP gOldStdTextProc;
QDRectUPP gOldRectProc;
Str255 gReplacementLines[kTextBoxes];
Handle gFakeWindowUserItemsDITL[kTextBoxes];
Handle gFakeWindowEditTextItemsDITL[kTextBoxes];
short gOccludeItem;
short gLastOldItem;
short gKiboshErase;
short gEditingItem;
void
main(void)
{
Handle initHandle;
initHandle = ReturnA0();
{
int i;
EnterCodeResource();
PrepareCallback();
DetachResource(initHandle);
HLock(initHandle);
gFakeWindowUserItemDITL = GetResource('DITL', 129);
DetachResource(gFakeWindowUserItemDITL);
HLock(gFakeWindowUserItemDITL);
for (i = 0; i < kTextBoxes; i++)
{
gFakeWindowEditTextItemsDITL[i] = GetResource('DITL', 512 + i);
DetachResource(gFakeWindowEditTextItemsDITL[i]);
HLock(gFakeWindowEditTextItemsDITL[i]);
gReplacementLines[i][0] = 0;
}
gOldTEInit = GetToolTrapAddress(_TEInit);
SetToolTrapAddress((UniversalProcPtr) TEInitPatch, _TEInit);
gAboutMacWindow = nil;
gFakeAboutMacWindow = nil;
gShouldCreateWindow = 0;
gEditTextItemIsEnabled = 0;
gOccludeItem = 0;
gKiboshErase = 0;
gEditingItem = 0;
ExitCodeResource();
}
}
pascal static void TEInitPatch(void)
{
UniversalProcPtr oldTEInit;
StringPtr curApName;
EnterCallback();
curApName = LMGetCurApName();
if (*(OSType *) curApName == 0x0646696E)
{
gOldMenuSelect = (MenuSelectProcPtr) GetToolTrapAddress(_MenuSelect);
gOldNewCWindow = (NewCWindowProcPtr) GetToolTrapAddress(_NewCWindow);
// gOldShowWindow = (ShowWindowProcPtr) GetToolTrapAddress(_ShowWindow);
gOldIsDialogEvent = (IsDialogEventProcPtr) GetToolTrapAddress(_IsDialogEvent);
// gOldDialogSelect = (DialogSelectProcPtr) GetToolTrapAddress(_DialogSelect);
gOldDisposeWindow = (DisposeWindowProcPtr) GetToolTrapAddress(_DisposeWindow);
SetToolTrapAddress((UniversalProcPtr) MenuSelectPatch, _MenuSelect);
SetToolTrapAddress((UniversalProcPtr) NewCWindowPatch, _NewCWindow);
// SetToolTrapAddress((UniversalProcPtr) ShowWindowPatch, _ShowWindow);
SetToolTrapAddress((UniversalProcPtr) IsDialogEventPatch, _IsDialogEvent);
// SetToolTrapAddress((UniversalProcPtr) DialogSelectPatch, _DialogSelect);
SetToolTrapAddress((UniversalProcPtr) DisposeWindowPatch, _DisposeWindow);
}
oldTEInit = gOldTEInit;
(*oldTEInit)();
ExitCallback();
}
pascal static long MenuSelectPatch(Point select)
{
long retMenu;
EnterCallback();
retMenu = (*gOldMenuSelect)(select);
gShouldCreateWindow = (retMenu == 0x01000001 && !gFakeAboutMacWindow);
ExitCallback();
return retMenu;
}
pascal static WindowPtr NewCWindowPatch(void *wStorage, const Rect *boundsRect,
ConstStr255Param title, Boolean visible, short procID, WindowRef behind,
Boolean goAwayFlag, long refCon)
{
register WindowPtr newWindow;
Boolean inProgress = 0;
EnterCallback();
if (gShouldCreateWindow != 0)
{
inProgress = 1;
gShouldCreateWindow = 0;
newWindow = gFakeAboutMacWindow = NewColorDialog(&gFakeAboutMacWindowStorage, boundsRect, title, visible, procID, behind, goAwayFlag, refCon, gFakeWindowUserItemDITL);
SetStdCProcs(&gReplacementProcs);
gOldStdTextProc = gReplacementProcs.textProc;
gReplacementProcs.textProc = ReplStdText;
gOldRectProc = gReplacementProcs.rectProc;
gReplacementProcs.rectProc = ReplRect;
((CGrafPtr) gFakeAboutMacWindow)->grafProcs = &gReplacementProcs;
// GetDialogItem(newWindow, kDialogUserItem1, &itemType, &itemHandle, &itemRect);
// itemHandle = (Handle) UserItemHandler;
// SetDialogItem(newWindow, kDialogUserItem, itemType, itemHandle, &itemRect);
// gFakeWindowTextRect = itemRect;
}
else
newWindow = (*gOldNewCWindow)(wStorage, boundsRect, title, visible, procID, behind, goAwayFlag, refCon);
if (inProgress)
gAboutMacWindow = newWindow;
ExitCallback();
return(newWindow);
}
pascal static unsigned short IsDialogEventPatch(const EventRecord* theEvent)
{
short savedWindowKind;
register unsigned short result;
short makeADialog = true;
short callDialogSelect = false;
EnterCallback();
if (makeADialog && gFakeAboutMacWindow)
{
savedWindowKind = ((WindowRecord *) gFakeAboutMacWindow)->windowKind;
((WindowRecord *) gFakeAboutMacWindow)->windowKind = kDialogWindowKind;
}
result = (*gOldIsDialogEvent)(theEvent);
if (gFakeAboutMacWindow && result)
{
switch (theEvent->what)
{
case nullEvent:
callDialogSelect = true;
break;
case updateEvt:
case activateEvt:
callDialogSelect = ((WindowPtr) theEvent->message == gFakeAboutMacWindow);
break;
case mouseDown:
case mouseUp:
{
WindowPtr whatWindow;
if (FindWindow(theEvent->where,&whatWindow) && whatWindow == gFakeAboutMacWindow)
{
callDialogSelect = true;
}
}
break;
case keyDown:
case keyUp:
case autoKey:
case app4Evt: // suspend/resume
callDialogSelect = (FrontWindow() == gFakeAboutMacWindow);
break;
}
if (callDialogSelect)
{
DialogPtr ourDialog;
short ourItem;
RgnHandle savedUpdate = 0;
if (theEvent->what == updateEvt)
{
savedUpdate = NewRgn();
if (savedUpdate)
CopyRgn(((WindowPeek) gFakeAboutMacWindow)->updateRgn,savedUpdate);
}
// callDialogSelect for our window
if (DialogSelect(theEvent,&ourDialog,&ourItem))
{
// This is an event for our window. Is it a mousedown?
if ((ourItem >= kDialogUserItem1) && (ourItem <= kDialogUserItem8) && (!gEditTextItemIsEnabled))
{
GrafPtr savedPort;
RGBColor savedBack;
RGBColor whiteColor;
short oldCount;
short itemType;
Handle itemHandle;
Rect itemRect;
Style faceStyle;
// GetPort(&savedPort);
// SetPort(ourDialog);
// GetBackColor(&savedBack);
// whiteColor.red = whiteColor.blue = whiteColor.green = 0xFFFF;
// RGBBackColor(&whiteColor);
// GetDialogItem(ourDialog, ourItem, &itemType, &itemHandle, &itemRect);
gLastOldItem = oldCount = CountDITL(ourDialog);
gEditingItem = ourItem;
// EraseRect(&itemRect);
// RGBBackColor(&savedBack);
AppendDITL(ourDialog, gFakeWindowEditTextItemsDITL[ourItem - kDialogUserItem1], overlayDITL);
gFakeItems = CountDITL(ourDialog) - oldCount;
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txFont = 1; // geneva
faceStyle = normal;
switch (ourItem)
{
case 1:
case 2:
case 5:
case 7:
faceStyle = bold;
break;
case 3:
faceStyle = bold + condense;
break;
}
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txFace = faceStyle;
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txSize = 9;
// gOccludeLine1 = 1; // turn off first line for now
gEditTextItemIsEnabled = true;
// SetPort(savedPort);
}
/*
if (ourItem == kDialogUserItem)
{
if (!gEditTextItemIsEnabled)
{
GrafPtr savedPort;
RGBColor savedBack;
RGBColor whiteColor;
short oldCount;
Debugger();
GetPort(&savedPort);
SetPort(ourDialog);
GetBackColor(&savedBack);
whiteColor.red = whiteColor.blue = whiteColor.green = 0xFFFF;
RGBBackColor(&whiteColor);
EraseRect(&gFakeWindowTextRect);
RGBBackColor(&savedBack);
SetPort(savedPort);
gLastOldItem = oldCount = CountDITL(ourDialog);
AppendDITL(ourDialog, gFakeWindowEditTextItemDITL, overlayDITL);
gFakeItems = CountDITL(ourDialog) - oldCount;
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txFont = 1; // geneva
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txFace = bold;
(*(((DialogPeek) gFakeAboutMacWindow)->textH))->txSize = 9;
gOccludeLine1 = 1; // turn off first line for now
gEditTextItemIsEnabled = true;
}
}
*/
if (ourItem == gLastOldItem+1)
{
if (theEvent->what == keyDown)
{
if (((theEvent->message & charCodeMask)) == 13)
{
if (gEditTextItemIsEnabled)
{
short iType;
Handle iHandle;
Rect iRect;
GetDItem(ourDialog,gLastOldItem+1,&iType,&iHandle,&iRect);
GetIText(iHandle,gReplacementLines[gEditingItem - kDialogUserItem1]);
ShortenDITL(ourDialog, gFakeItems);
gEditingItem = 0;
gEditTextItemIsEnabled = false;
gOccludeItem = 0;
}
}
}
}
}
else
{
/* Debugger();
if (gEditTextItemIsEnabled)
{
ShortenDITL(ourDialog, gFakeItems);
gEditTextItemIsEnabled = false;
}
*/ }
if (ourDialog == gFakeAboutMacWindow && savedUpdate)
CopyRgn(savedUpdate,((WindowPeek) gFakeAboutMacWindow)->updateRgn);
if (savedUpdate)
DisposeRgn(savedUpdate);
result = false; // we handled it already
}
}
// Now we override stuff
// if (result)
// {
// if (theEvent->what == keyDown && (theEvent->modifiers & cmdKey))
// result = false; // command keys go to the finder, override ZXCV back later
// }
if (makeADialog && gFakeAboutMacWindow)
{
((WindowRecord *) gFakeAboutMacWindow)->windowKind = savedWindowKind;
}
ExitCallback();
return(result);
}
/*pascal static Boolean DialogSelectPatch(const EventRecord* theEvent, DialogPtr* theDialog, short* itemHit)
{
short savedWindowKind;
register Boolean result;
short realItem;
DialogPtr realDialog;
RgnHandle savedUpdate = 0;
EnterCallback();
if (gFakeAboutMacWindow)
{
savedWindowKind = ((WindowRecord *) gFakeAboutMacWindow)->windowKind;
((WindowRecord *) gFakeAboutMacWindow)->windowKind = kDialogWindowKind;
if (theEvent->what == updateEvt)
{
savedUpdate = NewRgn();
if (savedUpdate)
CopyRgn(((WindowPeek) gFakeAboutMacWindow)->updateRgn,savedUpdate);
}
}
realDialog = *theDialog;
realItem = *itemHit;
result = (*gOldDialogSelect)(theEvent, &realDialog, &realItem);
if (gFakeAboutMacWindow && realDialog == gFakeAboutMacWindow)
{
result = false; // you never saw me, I was never here
}
else
{
*theDialog = realDialog;
*itemHit = realItem;
}
if (gFakeAboutMacWindow)
{
if (realDialog == gFakeAboutMacWindow && savedUpdate)
CopyRgn(savedUpdate,((WindowPeek) gFakeAboutMacWindow)->updateRgn);
if (savedUpdate)
DisposeRgn(savedUpdate);
((WindowRecord *) gFakeAboutMacWindow)->windowKind = savedWindowKind;
}
ExitCallback();
return(result);
}
*/
pascal static void DisposeWindowPatch(WindowPtr whichWindow)
{
EnterCallback();
if (gFakeAboutMacWindow && whichWindow == gFakeAboutMacWindow)
{
gFakeAboutMacWindow = 0;
CloseDialog(whichWindow);
}
else
{
(*gOldDisposeWindow)(whichWindow);
}
ExitCallback();
}
/*pascal static void
UserItemHandler(WindowRef theWindow, short item)
{
Debugger();
}
*/
pascal static void ReplStdText(short count, char* textAddr, Point numer, Point denom)
{
Point startPoint;
EnterCallback();
// if (gFakeAboutMacWindow->pnLoc.h > 100 &&
// gFakeAboutMacWindow->pnLoc.v < 20)
// {0x14, 0xc0, 0x14, 0x162} "system software"
// 0x120, 0x14 is "7.5.3"
// {0x23, 0xc0, 0x23, 0x162} "rev 2"
// {0x32, 0x35, 0x32, 0x90} "Power Mac"
// {0x32, 0xc0, 0x32, 0x162} "Copyright"
// {0x4e, 0x11, 0x4e, 0x61} "Total Memory"
// {0x4e, 0x87, 0x4e, 0xaf} "value of Total Memory"
// {0x4e, 0xc0, 0x4e, 0x138} "Largest Unused Block"
// {0x4e, 0x142, 0x4e, 0x16a} "value of Largest Unused Block"
// To handle ascender and descender, we will take a constant height of each
// line, this has been empiracally determined to be 14 pixels. So, we distribute
// 11 to above, 3 below
startPoint = gFakeAboutMacWindow->pnLoc;
// "system software"
if (startPoint.h == 0xc0 &&
startPoint.v == 0x14 &&
gReplacementLines[0][0])
{
// Debugger();
(*gOldStdTextProc)(gReplacementLines[0][0],(char*) &gReplacementLines[0][1],numer,denom);
gKiboshErase = 1;
}
else if (startPoint.h == 0x120 &&
startPoint.v == 0x14 &&
gReplacementLines[0][0])
{ // "7.5.3"
// nothing
// Debugger();
gKiboshErase = 0;
}
else if ((startPoint.v == 0x23) && (startPoint.h == 0xc0) && gReplacementLines[1][0]) // "rev 2"
{
(*gOldStdTextProc)(gReplacementLines[1][0], (char *) &gReplacementLines[1][1],numer,denom);
}
else if ((startPoint.v == 0x32) && (startPoint.h == 0x35) && gReplacementLines[2][0]) // "Power Mac"
{
(*gOldStdTextProc)(gReplacementLines[2][0], (char *) &gReplacementLines[2][1],numer,denom);
}
else if ((startPoint.v == 0x32) && (startPoint.h == 0xc0) && gReplacementLines[3][0]) // "Copyright"
{
(*gOldStdTextProc)(gReplacementLines[3][0], (char *) &gReplacementLines[3][1],numer,denom);
}
else if ((startPoint.v == 0x4e) && (startPoint.h == 0x11) && gReplacementLines[4][0]) // "Total Memory"
{
(*gOldStdTextProc)(gReplacementLines[4][0], (char *) &gReplacementLines[4][1],numer,denom);
}
else if ((startPoint.v == 0x4e) && (startPoint.h == 0x87) && gReplacementLines[5][0]) // "value of Total Memory"
{
(*gOldStdTextProc)(gReplacementLines[5][0], (char *) &gReplacementLines[5][1],numer,denom);
}
else if ((startPoint.v == 0x4e) && (startPoint.h == 0xc0) && gReplacementLines[6][0]) // "Largest Unused Block"
{
(*gOldStdTextProc)(gReplacementLines[6][0], (char *) &gReplacementLines[6][1],numer,denom);
}
else if ((startPoint.v == 0x4e) && (startPoint.h == 0x142) && gReplacementLines[7][0]) // "value of Largest Unused Block"
{
(*gOldStdTextProc)(gReplacementLines[7][0], (char *) &gReplacementLines[7][1],numer,denom);
}
else
(*gOldStdTextProc)(count,textAddr,numer,denom); // sick, sick!
ExitCallback();
}
pascal static void ReplRect(GrafVerb verb, Rect *r)
{
EnterCallback();
if (!gKiboshErase || (verb != erase))
(*gOldRectProc)(verb,r);
ExitCallback();
}